<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //splice(删除的索引，删除几个)
      // 参数：(删除的索引，删除几个)
      // 作用：删除任意元素
      // 返回值：被删除的数
      const arr = ['a', 'b', 'c']
      const res = arr.splice(2, 1)
      console.log(arr) //a,b
      console.log(res) //c

      const res1 = arr.splice(1)
      console.log(arr)//b


      //拓展
      //splice(删除的索引，删除几个,追加)
      //追加任意几个
      const arr2 = ['a', 'b', 'c']
      const res2=arr2.splice(2,1,'pig')
      console.log(arr2);

      //在前面追加
      arr2.splice(2,0,'dog')
      console.log(arr2);
    </script>
  </body>
</html>
